package common {
	import laya.d3.component.Script;
	import laya.d3.core.BaseCamera;
	import laya.d3.core.Camera;
	import laya.d3.core.Sprite3D;
	import laya.d3.core.render.RenderState;
	import laya.d3.core.scene.Scene;
	import laya.d3.core.scene.Scene;
	import laya.d3.math.Quaternion;
	import laya.d3.math.Vector3;
	import laya.events.Event;
	import laya.events.KeyBoardManager;
	import laya.d3.math.Vector2;
	import laya.d3.component.physics.Collider;
	
	/**
	 * ...
	 * @author
	 */
	public class TargetMoveScript extends Script {
		//移动类型
		private var moveType:int;
		private var target:Target;
		private var speed:Number = 0;
		private var position:Vector3 = new Vector3();
		private var sin:Number;
		private var cos:Number;
		private var speedParam:Number = 0.02;
		public var isPause:Boolean = false;
		public function TargetMoveScript() {
			
		}

		public function setMoveType(type:int = 1):void
		{
			moveType = type;
		}
		
		override public function _initialize(owner:Sprite3D):void {
			super._initialize(owner);
			target = owner as Target;
			var speed:Number = Math.random() * speedParam - speedParam/2;
			sin = Math.sin(speed).toFixed(2);
			cos = Math.cos(speed).toFixed(2);
		}
		
		override public function _update(state:RenderState):void {
			super._update(state);
			moveUpdate();
		}

		private function moveUpdate():void
		{
			if(isPause)
				return;
			if(moveType == Target.MOVE_TYPE_1)
			{
				return;
			}
			else if(moveType == Target.MOVE_TYPE_2)
			{
				position.x = target.transform.position.x * cos - target.transform.position.z * sin;
				position.z = target.transform.position.x * sin + target.transform.position.z * cos;
				position.y = target.transform.position.y;
				target.transform.position = position;
			}
		}
	}

}